import 'package:equatable/equatable.dart';
import 'package:website.core/core/domain/entities/user.dart';

const kApiUserIdKey = 'id';
const kApiUserEmailKey = 'email';

class ApiUserDto extends Equatable {
  const ApiUserDto._internal({
    required this.id,
    required this.email,
  });

  final String id;
  final String email;

  @override
  List<Object?> get props {
    return [
      id,
      email,
    ];
  }

  factory ApiUserDto.fromJson(Map<String, dynamic> json) {
    return ApiUserDto._internal(
      id: json[kApiUserIdKey],
      email: json[kApiUserEmailKey],
    );
  }

  factory ApiUserDto.fromEntity(User user) {
    return ApiUserDto._internal(
      id: user.id,
      email: user.email,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      kApiUserIdKey: id,
      kApiUserEmailKey: email,
    };
  }

  User toEntity() {
    return User(
      id: id,
      email: email,
    );
  }
}
